﻿ 
//验证验证码是否正确
function ValidateCode(source,arguments)
{
	var flag = false;
	var code=arguments.Value;
	var postParam="ckvcode="+code;
	createXMLHttpRequest();	
	xmlHttp.open("POST",codeUrl,false);
	xmlHttp.onreadystatechange=function()
	{	
	    if(xmlHttp.readyState==4)
	    {	
		    if(xmlHttp.status==200)
		    {	
			    var result=xmlHttp.responseText;
			    if(result=='true'){flag=true;}
		    }
	    }
	};
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");	
	xmlHttp.send(postParam);
	arguments.IsValid=flag;
}
 
//获得新的验证码
function getNewCode(o)
{
	var obj=$(o);
	obj.src="/Include/ValidateCode.aspx?"+Math.random();
	
}
function disableBtn(obj)
{
	obj.disabled='disabled';
	
}
function goUrl(url)
{
	window.location.href=url;
	
}
//替换Url QueryString
function RegularUrl(url,key,value)

{
	var fragPos=url.lastIndexOf("#");
	var fragment="";	
	if(fragPos>-1)
	{
		fragment=url.substring(fragPos);
		url=url.substring(0,fragPos);
		
	}
	var querystart=url.indexOf("?");	
	if(querystart<0)
	{
		url+="?"+key+"="+value;
		
	}
	else if(querystart==url.length-1)
	{
		url+=key+"="+value;
		
	}
	else 
	{
		var Re=new RegExp(key+"=[^\\s&#]*","gi");		
		if(Re.test(url))url=url.replace(Re,key+"="+value);		
		else url+="&"+key+"="+value;
		
	}
	return url+fragment;
	
}
//防止按钮重复提交
function onceSubmit(obj)
{
	if(typeof(Page_ClientValidate)=='function')
	{
		if(Page_ClientValidate()==false)
		{
			return false;
		}
	}obj.disabled='disabled';
}

//验证码验证
function ValidateCode1(code)
{
	var flag = false;
	var postParam="ckvcode="+code;
	createXMLHttpRequest();	
	xmlHttp.onreadystatechange=function()
	{
	    if(xmlHttp.readyState==4)
	    {
		    if(xmlHttp.status==200)
		    {
			    var result=xmlHttp.responseText;
			    if(result=='true'){flag=true;}
		    }
	    }
	};
	xmlHttp.open("POST",codeUrl,false);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");	
	xmlHttp.send(postParam);
	return flag;
}

//编码字符串
function encodeUrl(str)
{
    return escape(str);
}
//获得TreeView选择的值，并以;隔开
function getTreeViewValue(obj)
{
    var checkValue="";
	var TreeView=obj;//"";
	var checkNode=document.getElementById("CheckedNode");
	var checkboxs=document.getElementById(TreeView).getElementsByTagName("input");
	for(i=0;i<checkboxs.length;i++)
	{
		if(checkboxs[i].type=="checkbox"
		&&checkboxs[i].name.substr(0,TreeView.length)==TreeView
		&&checkboxs[i].checked)
		{
			checkValue+=checkboxs[i].title+";";
		}
	}
	return checkValue;
}

//弹出选择框
function showWindow(url,width,height)
{	
    return window.showModalDialog(url,"newform",
    "dialogWidth:"+width+"px;dialogHeight:"+height+"px;status:no;scroll:no");
}

//javascript utils
String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g,"");
}
var Utils = new Object();
Utils.addEventHandler = function (oTarget, sEventType, fnHandler) {
     if (oTarget.addEventListener) {
         oTarget.addEventListener(sEventType, fnHandler, false);
     }
     else if (oTarget.attachEvent) {
         oTarget.attachEvent("on" + sEventType, fnHandler);
     }
     else {
         oTarget["on" + sEventType] = fnHandler;
     }
};   
Utils.removeEventHandler = function (oTarget, sEventType, fnHandler) {
     if (oTarget.removeEventListener) {
         oTarget.removeEventListener(sEventType, fnHandler, false);
     } else if (oTarget.detachEvent) {
         oTarget.detachEvent("on" + sEventType, fnHandler);
     } else {
         oTarget["on" + sEventType] = null;
     }
};
Utils.delegate=function(caller, fnc)
{
    var delegate = function()
    {
        fnc.apply(caller, arguments);
    }
    return delegate;
};
Utils.$=function(s)
{
    var obj;
    if(typeof(s)=="string")
    {
        obj= document.getElementById(s);
    }
    else
    {
        obj=s; 
    }
    return obj;
};
 Utils.GetElemWidth=function(elem)
 {
  var xPos = elem.style.pixelWidth|elem.offsetWidth;
  return xPos;
 }
 Utils.GetElemHeight=function(elem)
 {
  var yPos = elem.style.pixelHeight|elem.offsetHeight;
  return yPos;
 }
  Utils.changeOpac=function(objT,opacity) {
    var obj=objT.style; 
    obj.opacity = (opacity / 100);
    obj.MozOpacity = (opacity / 100);
    obj.KhtmlOpacity = (opacity / 100);
    obj.filter = "alpha(opacity=" + opacity + ")";
}

//----------------Js获取URL参数值 开始---------------
function Request(paras) {
    var url = location.href;
    var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
    var paraObj = {}
    for (i = 0; j = paraString[i]; i++) {
        paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
    }
    var returnValue = paraObj[paras.toLowerCase()];
    if (typeof (returnValue) == "undefined") {
        return "";
    } else {
        return returnValue;
    }
} 
//----------------Js获取URL参数值 结束--------------- 
function CheckValue() {
    var bepost = "";
    $("[name='cb']").each(function (i, cb) {
        if (cb.checked) {
            bepost += (cb.value + "|");
        }
    });
    if (bepost == 0) {
        alert("你没有选中任何项?!");
        return "";
    }
    return bepost;
}

//josn返回时间格式格式化
function ChangeDateFormat(cellval) {
    var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10));
    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    var currentHH = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    var currentmm = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    var currentss = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    return date.getFullYear() + "-" + month + "-"
    + currentDate + " " + currentHH + ":" + currentmm + ":" + currentss;
}
 
function fDate() {
    dt = new Date();
    y = dt.getFullYear();
    m = dt.getMonth() + 1;
    d = dt.getDate();
    h = dt.getHours();
    mm = dt.getMinutes();
    ss = dt.getSeconds();
    m = m < 10 ? '0' + m : m;
    d = d < 10 ? '0' + d : d;
    s = y + "-" + m + "-" + d + " " + h + ":" + mm + ":" + ss;
    return s;
}